const esbuild = require("esbuild");
const path = require("path");
const { utils } = require("xlsx");
const logger = require("./utils-log");
const bs = require("browser-sync").create("game");

const dir = path.resolve(__dirname, "../");
const bsName = "game";

const cacheBundle = null;


function run(cb) {

    bs.init({
        server: path.join(dir, "bin"),
        files: ["bin/js/*.js"],
        logConnections: false,
        logPrefix: bsName,
        open: false,
        notify: false
    });

    // bs.watch(path.join(dir, "src"),
    //     {
    //         persistent: true,
    //         ignoreInitial: true
    //     },

    //     esbuild_build


    // );
}

function esbuild_build() {
    console.log("esbuild_build");
    return esbuild.build({
        bundle: true,
        sourcemap: true,
        tsconfig: path.join(dir, "tsconfig.json"),
        entryPoints: ["src/Main.ts"],
        format: "iife",
        // charset: "ascii",
        metafile: false,
        write: true,
        outfile: path.join(dir, "bin/js/bundle.js"),
    })
}

module.exports = esbuild_build;